﻿<?xml version="1.0" encoding="utf-8" ?>
<AdoNetDataAccess connection="$SyrinxDBConnection$" formatter="bizobjlist of TreeNode">
<FormatterInfo>
    <code for="vars" on="TreeNode">
    bool stripLeading = true;
    bool setup = false;
  </code>
  <code for="postEach" on="TreeNode">
    <![CDATA[
			try
			{
        if(!setup)
        {
          if(info.get("stripLeading") is bool)
            stripLeading = (bool)info.get("stripLeading");
          else if(info.get("stripLeading") is string)
            stripLeading = (string.Compare((string)info.get("stripLeading"), "False", true) == 0)?false:true;
          setup = true;
        }
          
        if(stripLeading)
        {
          string title = (string)CurrentBizObj.get("name");
          int titIndex = title.IndexOf("~!");
          if(titIndex != -1)
            CurrentBizObj.put("name", title.Substring(titIndex+2));
        }
			}
			catch(Exception e)
			{
			}
		]]>
  </code>
</FormatterInfo>
    <Sql>
      SELECT DISTINCT 
          t1.id, c.name, c.depth, c.keyName, t2.parentHostId, c.treeName,
          c.lastChildUpdated as counts_lastChildUpdated, c.lastChildUpdatedByUserId as counts_lastChildUpdatedBy_id,
          c.totalL1 AS counts_totalL1, c.totalL2 AS counts_totalL2, c.totalL3 AS counts_totalL3, c.totalL4 AS counts_totalL4
      FROM 
          ObjectTreeNodes AS t2 INNER JOIN
          ObjectTreeNodes AS t1 ON t2.parentHostId = t1.id INNER JOIN
          ObjectTreeCounts AS c ON t1.objectId = c.objectId
      WHERE
          (t2.objectId = @id)
      ORDER BY c.depth <code><![CDATA[sql.Append(info.get("dir"));]]></code>
	</Sql>
	<Param name="id" type="UniqueIdentifier"/>
</AdoNetDataAccess>